package top.zhangjianyong.tools.controller;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import top.zhangjianyong.tools.entity.guanjiangyuan.House;
import top.zhangjianyong.tools.entity.guanjiangyuan.People;
import top.zhangjianyong.tools.service.api.GuanjianyuanService;
import top.zhangjianyong.tools.utils.ApiResponse;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ： zhangjianyong
 * @date ： 2023/7/5 12:31 PM
 */
@RestController
@RequestMapping("/guanjiangyuan")
public class GuanjianyuanController {

    @Autowired
    private GuanjianyuanService guanjianyuanService;

    @PostMapping("/house/add")
    public ApiResponse add(@RequestBody House house) {
        return guanjianyuanService.add(house);
    }

    @PostMapping("/house/del/{id}")
    public ApiResponse del(@PathVariable("id") String id) {
        return guanjianyuanService.del(id);
    }

    @PostMapping("/house/update")
    public ApiResponse update(@RequestBody House house) {
        return guanjianyuanService.update(house);
    }

    @PostMapping("/house/search")
    public ApiResponse searchHouse(@RequestParam("searchKey") String key) {
        return guanjianyuanService.searchHouse(key);
    }

    @PostMapping("/people/list/{houseNo}")
    public ApiResponse peopleList(@PathVariable("houseNo") String houseNo) {
        return guanjianyuanService.peopleList(houseNo);
    }

    @PostMapping("/people/add")
    public ApiResponse peopleAdd(@RequestBody People people) {
        return guanjianyuanService.peopleAdd(people);
    }

    @PostMapping("/people/update")
    public ApiResponse peopleUpdate(@RequestBody People people) {
        return guanjianyuanService.peopleUpdate(people);
    }

    @PostMapping("/people/del/{id}")
    public ApiResponse peopleUpdate(@PathVariable String id) {
        return guanjianyuanService.peopleDel(id);
    }

    @GetMapping("/download")
    public ApiResponse peopleUpdate(HttpServletResponse response) throws IOException {

        return guanjianyuanService.download(response);
    }
}
